#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t,n,a[222222],mx=-1;
int rn(string s)
{
    int ans=0,r=-1,b=-1 ;
    for(int i=0;i<n;i++){
        if(s[i]=='r'&&r==a[i])ans+=a[i];
        if(s[i]=='b'&&b==a[i])ans+=a[i];
        if(s[i]=='r')r=a[i];if(s[i]=='b')b=a[i];
    }
    return ans;
}
void dfs(int p,string s){
    if(p==n){
        mx=max(mx,rn(s));
        return;
    }
    dfs(p+1,s+'r');
    dfs(p+1,s+'b');
    return;
}
int main()
{
    freopen("color.out","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int p=0;p<t;p++){
        cin>>n;
        for(int i=0;i<n;i++)cin>>a[i];
        string s="";
        dfs(0,s);
        cout<<mx<<endl;
        mx=-1;
    }
    return 0;
}

